﻿using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using PhillyCodeCamp.Domain.Validation;
using PhillyCodeCampSpecs.Helpers;

namespace PhillyCodeCampSpecs.Domain.Validation
{
    [TestFixture]
    public class When_Object_Doesnt_Pass_Validation
    {
        private IBusinessRule<IPerson> _failingBusinessRule;
        private IBusinessRule<IPerson> _failingBusinessRule2;
        private IBusinessRule<IPerson> _succeedingBusinessRule;
        private IPerson _person;
        private IBusinessRuleSet _ruleSet;

        [Test]
        public void Should_Retrieve_All_Broken_Rules()
        {
            IBusinessRuleSet brokenRules = _ruleSet.BrokenBy(_person);

            Assert.AreEqual(2, brokenRules.Count);

        }

        [Test]
        public void Should_Retrieve_Messages_For_All_Rules()
        {
            IBusinessRuleSet brokenRules = _ruleSet.BrokenBy(_person);
            IList<string> ruleMessages = brokenRules.Messages;

            Assert.Contains(_failingBusinessRule.Description, (IList)ruleMessages);
        }

        [TestFixtureSetUp]
        public void Context()
        {
            _failingBusinessRule = ObjectMother.CreateFailingBusinessRule();
            _failingBusinessRule2 = ObjectMother.CreateFailingBusinessRule2();
            _succeedingBusinessRule = ObjectMother.CreateSucceedingBusinessRule();

            _person = ObjectMother.CreateEmptyPerson();
            _ruleSet = new BusinessRuleSet<IPerson>(_failingBusinessRule, _failingBusinessRule2, _succeedingBusinessRule);
        }


    }

}

